<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<section class="container-fuld affix t-top">
    <div class="nav">
        <div class="container">
            <span class="logo">LIPE</span>
            <ul id="headmenu" class="nav-list">
                <li><a id="page1" href="${ctx}/index.jsp" class="active">首页</a></li>
                <li><a id="page2" href="${ctx}/showDesigner.jsp">设计师</a></li>
                <li><a id="page3" href="${ctx}/news.jsp">咨询</a></li>
            </ul>

            <div class="nav-tool">
                <%--<div class="i-search">--%>
                    <%--<input type="text" class="i-search-input" placeholder="请输入关键词搜索"/>--%>
                    <%--<button type="submit" class="btn-search">--%>
                        <%--<span class="icon icon-serch-black"></span>--%>
                    <%--</button>--%>
                <%--</div>--%>
                <ul class="list">
                    <li class="login jsLogin"><a href="">登录</a></li>
                    <li class="login jsReg"><a href="">注册</a></li>
                    <li id="personcenter_icon" class="login jsPersonCenter hide"><a id="personcenter_href"
                                                                                    href="#">个人中心</a></li>
                </ul>
            </div>
        </div>
    </div>
</section>

<script src="${ctx}/js/jquery.min.js"></script>
<script src="${ctx}/js/validate/jquery.validate.min.js"></script>
<script src="${ctx}/js/validate/messages_zh.js"></script>
<script src="${ctx}/js/jquery.slide.1.0.0.js"></script>
<script src="${ctx}/js/init.js"></script>
<script src="${ctx}/js/jqPaginator.js"></script>
<script src="${ctx}/js/jquery.paginate.js"></script>
<script src="${ctx}/js/jquery.dialog.js"></script>
<script src="${ctx}/js/temp.js"></script>
<script type="text/javascript" src="${ctx}/resources/plugins/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.form.js"></script>
<style>
    .gray {
        background: #E6E6E6;
        color: #818080;
        border: 1px solid #CCCCCC;
    }
</style>
<script>
    //发送短信验证码
    function sendSMSCode() {
        var phone = $("#phone").val();
        $.ajax({
            url: '${ctx}/customer/sendSMSValidCode.do',
            data: {phone: phone},
            success: function (res) {

            }, error: function (res) {

            }
        });
    }

    function start_sms_button(obj) {
        var count = 1;
        var sum = 30;
        var i = setInterval(function () {
            if (count > 10) {
                obj.attr('disabled', false);
                obj.val('发送验证码');
                clearInterval(i);
            } else {
                obj.val('剩余' + parseInt(sum - count) + '秒');
            }
            count++;
        }, 1000);
    }

    var test = {
        node: null,
        count: 60,
        start: function () {
            //console.log(this.count);
            if (this.count > 0) {
                this.node.innerHTML = this.count--;
                var _this = this;
                setTimeout(function () {
                    _this.start();
                }, 1000);
            } else {
                this.node.removeAttribute("disabled");
                this.node.innerHTML = "再次发送";
                this.count = 60;
            }
        },
        //初始化
        init: function (node) {
            this.node = node;
            this.node.setAttribute("disabled", true);
            this.start();
        }
    };


    jQuery.validator.addMethod("phone", function (value, element) {
        var reg = /^1[3|4|5|8|9]\d{9}$/;
        return reg.test(value);
    }, "请填写正确的手机号");

    function changecode() {
        $("#invcode_reg").attr("src", '${ctx}/customer/createRandomCode.do?' + new Date().getTime());
    }
    function changecode2() {
        $("#invcode_login").attr("src", '${ctx}/customer/createRandomCode.do?' + new Date().getTime());
    }
    $(function () {

        //注册成功对话框
        var alt = $.dialog({
            html: temp.suHtml
        });

        var login_sccuess = $.dialog({
            html: temp.loginsuccessHtml
        });

        var validCode = true;
        $(document).on('click', '#sendSMSBtn', function () {
            var time = 60;
            var code = $(this);
            if (validCode) {
                validCode = false;
                code.addClass("gray");
                var t = setInterval(function () {
                    time--;
                    code.html(time + "秒");
                    if (time == 0) {
                        clearInterval(t);
                        code.html("重新获取");
                        validCode = true;
                        code.removeClass("gray");
                    }
                }, 1000)
                sendSMSCode();
            }
        });


        //登录对话框
        var login_dialog = $.dialog({
            html: temp.logHtml,
            callback: function () {
                $("#invcode_login").attr("src", '${ctx}/customer/createRandomCode.do');
                $('.btn-input').on('click', function () {
                    $("#loginform").ajaxSubmit({
                        url: '${ctx}/customer/login.do',
                        success: function (data) {
                            if (data.code == '0000') {
                                login_dialog.close();
                                login_sccuess.open();
                                setTimeout(function () {
                                    login_sccuess.close();
                                }, 2000);
                                $("#personcenter_icon").removeClass("hide");
                                $("#personcenter_href").attr("href", '${ctx}/customer/goPersonCenter.do?id=' + data.data.userid);
                            } else {
                                regDialg.close();
                                alert(data.msg);
                            }
                        }
                    });
                    return false;
                })
            }
        });

        var telDialog = $.dialog({
            title: '身份验证',
            html: temp.telIsRightHtml,
            callback: function () {
            }
        });
        //注册对话框
        var regDialg = $.dialog({
            html: temp.regHtml,
            callback: function () {
                changecode();
                var f = $("#regform").validate({
                    rules: {
                        phone: {
                            required: true,
                            phone: true
                        },

                        password: {
                            required: true,
                            minlength: 6
                        },
                        confirm_password: {
                            required: true,
                            minlength: 6,
                            equalTo: "#password"
                        }
                    },
                    messages: {
                        password: {
                            required: "请输入密码",
                            minlength: "密码不能小于6个字 符"
                        },
                        confirm_password: {
                            required: "请输入确认密码",
                            minlength: "确认密码不能小于6个字符",
                            equalTo: "两次输入密码不一致"
                        }
                    },
                    submitHandler: function (form) {
                        $("#regform").ajaxSubmit({
                            url: '${ctx}/customer/save.do',
                            success: function (data) {
                                if (data.code == '0000') {
                                    regDialg.close();
                                    alt.open();
                                } else {
                                    regDialg.close();
                                    alert(data.msg);
                                }
                            }
                        });
                    },
                    onsubmit: true // 是否在提交是验证
//                       	 onfocusout:false,// 是否在获取焦点时验证
//                       	 onkeyup :false,// 是否在敲击键盘时验证
                });
            }
        });

        $('.jsLogin').on('click', function () {
            login_dialog.open();
            changecode2();
            return false;
        });

        $('.jsReg').on('click', function () {
            //注册对话框
            regDialg.open();
            changecode();
            return false;
        });

        //修改电话号码
        $('.jsModifyTel').on('click', function () {
            var telDialog = $.dialog({
                title: '身份验证',
                html: temp.telIsRightHtml,
                callback: function () {
                    $('input[type=radio]').radio(); //美化radio样式


                    //绑定确定按钮事件
                    $('.jsIsOk').on('click', function () {
                        telDialog.close();
                        $('.jsModifyT').removeClass('hidden')
                                .siblings().hide();
                    })
                }
            });
            return false;
        });

        //点击修改邮箱
        $('.jsModifyEmail').on('click', function () {
            telDialog.open();
            return false;
        });

        //点击修改密码
        $('.jsModifyPassword').on('click', function () {
            telDialog.open();
            return false;
        });
//             //倒计时
        $('.jsSendCode').on('click', function () {
            backTimer('.jsSendCode');
            return false;
        });

    })

    //登录
    function doLogin() {

    }


    var currentUser = '${login_user.customerid}';
    $(document).ready(function () {
        if (currentUser == '') {
            $("#personcenter_icon").addClass("hide");
        } else {
            $("#personcenter_icon").removeClass("hide");
            $("#personcenter_href").attr("href", '${ctx}/customer/goPersonCenter.do?id=' + currentUser);
        }
    });
</script>